package game;

import game.resources.LogWriter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class GameData {
	enumStates state;
	
    private int tilesPerPlayer;

    private int initialCash;

    private Board board;
    
    private Player[] players;
    
    private List<Tile> tileList;

    private Company[] companies;
    
    int gameID;

    private String[] playerNames;

    private Map<Integer, List<Player>> finalStandings;
    
    @SuppressWarnings("unused")
    private List<Player> clientFinalStandings;

    private int currentPlayer;
    
    @SuppressWarnings("unused")
	private long currentPlayerUserID;

    private int skippedTurns;
    
    private LogWriter logWriter;
    
    private int actionCounter;

    public GameData(int gameID) {
        this.tilesPerPlayer = 6;
        this.initialCash = 6000;
        this.tileList = new ArrayList<Tile>();
        this.companies =  new Company[7];
        this.finalStandings = null;
        this.currentPlayer = 0;
        this.skippedTurns = 0;
        this.gameID = gameID; 
        this.actionCounter = 0;
    }
    
    // only after GameLogic.init!!!
    public void initLogWriter() {
    	this.logWriter = new LogWriter(gameID,playerNames);
    }

    public int getTilesPerPlayer() {
        return tilesPerPlayer;
    }

    public void setTilesPerPlayer(int tilesPerPlayer) {
        this.tilesPerPlayer = tilesPerPlayer;
    }

    public int getInitialCash() {
        return initialCash;
    }

    public void setInitialCash(int initialCash) {
        this.initialCash = initialCash;
    }

    public List<Tile> getTileList() {
        return tileList;
    }

    public void setTileList(List<Tile> tileList) {
        this.tileList = tileList;
    }

    public Board getBoard() {
        return board;
    }

    public void setBoard(Board board) {
        this.board = board;
    }

    public Company[] getCompanies() {
        return companies;
    }

    public void setCompanies(Company[] companies) {
        this.companies = companies;
    }

    public Player[] getPlayers() {
        return players;
    }

    public void setPlayers(Player[] players) {
        this.players = players;
    }
    
    public String[] getPlayerNames() {
        return playerNames;
    }

    public void setPlayerNames(String[] playerNames) {
        this.playerNames = playerNames;
    }

    public Map<Integer, List<Player>> getFinalStandings() {
        return finalStandings;
    }

    public void setFinalStandings(Map<Integer, List<Player>> finalStandings) {
        this.finalStandings = finalStandings;
    }

    public void setClientFinalStandings(List<Player> clientFinalStandings) {
        this.clientFinalStandings = clientFinalStandings;
    }
    
    public int getCurrentPlayer() {
        return currentPlayer;
    }
    
    public LogWriter getLogWriter() {
        return logWriter;
    }

    public void setCurrentPlayer(int currentPlayer) {
    	currentPlayerUserID = getPlayers()[currentPlayer].getUserID();
        this.currentPlayer = currentPlayer;
    }

    public int getSkippedTurns() {
        return skippedTurns;
    }

    public void setSkippedTurns(int skippedTurns) {
        this.skippedTurns = skippedTurns;
    }
    
    public int getActionCounter() {
        return actionCounter;
    }
    
    public void IncreaseActionCounter() {
        this.actionCounter++;
    }
    
    // ----------------------------------------------------------------------------- // 
    // Function parameters:
    Tile managePlaceTile_chosenTile = null;
    Coordinate managePlaceTile_chosenTileCoordinate;
    boolean managePlaceTile_tileCreateCompanyWhenAllOnBoard = false;    
  
    //this is just to flag whether we should increase skippedTurns or not -
    //if the player placed a tile between safe companies, and there are tiles in the bank,
    //he'll get a new tile so maybe he'll have a tile to place in the next round..
    boolean managePlaceTile_increaseSkipped = true;
    boolean managePlaceTile_firstTileBetweenSafeCompanies = true; //this is also for the same purpose..
    Tile managePlaceTile_NewlyPlacedTile = null;
    
    Tile[] manageCompanySell_neighbors;     
    Map<Integer, List<Company>> manageCompanySell_neighborCompanies;            
    int manageCompanySell_numOfNeighborCompanies;
    int manageCompanySell_times;
    Company manageCompanySell_buyingCompany;
    List<Company> manageCompanySell_SameSized1 = null;
    List<Company> manageCompanySell_SameSized2 = null;
    
    Company SellOrder_soldCompany;
    Company SellOrder_buyingCompany;
    enumCompany SellOrder_soldCompanyEnum;
    enumCompany SellOrder_buyingCompanyEnum;
    private int SellOrder_playerIndex;
    @SuppressWarnings("unused")
	private long SellOrder_playerIndexUserID;
    boolean SellOrder_firstTime;
    
    public void setSellOrder_playerIndex(int index) {
    	this.SellOrder_playerIndex = index;
    	SellOrder_playerIndexUserID = getPlayers()[index].getUserID();
    }
    
    public int getSellOrder_playerIndex() {
    	return SellOrder_playerIndex;
    }
    
    enumCompany startGame_createdCompany;
    boolean startGame_IsCreatedCompany;
    
    int manageCompanySellContinue_OuterIndex;
    int manageCompanySellContinue_InnerIndex;
    
    boolean sellCompanyToCompany_ReturnToEnd;
}